package com.csdj.t301.cloud.uitls;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

/**
 * author:cloud
 * date:2021/2/21 0021
 **/
public class SqlSessionUtil {
    private static SqlSessionFactory factory = null;

    public static SqlSession getSession(){
        if(factory == null){
            try {
                factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return factory.openSession();
    }
}
